﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Transcend.DP3.Helper
{
	public class ObjectHelper
	{

		/// <summary>
		/// 检查类型是否存在索引器
		/// </summary>
		public static bool HasIndexer(Type t)
		{
			var p = t.GetProperty("Item");
			if (p == null) return false;
			return p.GetIndexParameters().Length > 0;
		}

		/// <summary>
		/// 通过反射，取得索引器值
		/// </summary>
		public static object IndexerValue(object obj, string pName)
		{
			var t = obj.GetType();
			var p = t.GetProperty("Item");
			if (p == null) return null;
			return p.GetValue(obj, new object[] { pName });
		}

	}
}
